import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 2.0
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.0
import Db 1.0
import User 1.0
//import Draw 1.0
Rectangle {
    id: root
    visible: true
    width: 1280
    height: 800
    color: "cadetblue"
    property string authority: "null"
    property string username: "用户管理员"
    Dbutil{id:dboperate}
    User{id:user}
    //Draw{id:draw}
    Image {
        id: rocket
        anchors.fill: parent
        fillMode: Image.TileHorizontally
        smooth: true
        source: "qrc:///images/background.jpg"
    }
    Popup //登陆弹窗
    {
        id: myPopup
        width: 400
        height: 600
        x: (root.width - width) / 2
        y: (root.height - height) / 2
        topPadding: 0
        leftPadding: 0
        rightPadding: 0
        bottomPadding: 0
        modal: false
        focus: true
        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent

        Rectangle {
            width: parent.width
            height: parent.height
            Rectangle {
                width: parent.width
                height: 50
                color: "#002aff"
                Text {
                    x: 20
                    anchors.verticalCenter: parent.verticalCenter
                    text: "用户登陆/注销..."
                    color: "white"
                }
                Image {
                    id: close
                    y: 5
                    width: 40
                    height: 40
                    anchors.right: parent.right
                    source: "qrc:///images/close.png"
                    MouseArea {
                        anchors.fill: parent
                        acceptedButtons: Qt.LeftButton

                        onClicked: {
                            myPopup.close()
                        }
                    }
                }
            }
            Text {
                x: 40
                y: 65
                width: 60
                height: 30

                text: "用户名称："
            }
            ComboBox {
                id: combox
                x: 125
                y: 60
                width: 200
                height: 30
                currentIndex: 2
                model: ListModel {
                    id: cbItems
                    ListElement {
                        text: "用户管理员"
                    }
                    ListElement {
                        text: "系统管理员"
                    }
                    ListElement {
                        text: "客人"
                    }
                }

                onCurrentIndexChanged: {
                    username=cbItems.get(currentIndex).text
                }
            }
            Text {
                x: 40
                y: 105
                width: 60
                height: 30

                text: " 口 令："
            }
            Rectangle {
                x: 125
                y: 95
                width: 190
                height: 30
                border.color: "blue"
                TextInput {
                    id:passwd
                    width: parent.width
                    height: parent.height
                    echoMode: TextInput.Password
                    passwordCharacter: "*"
                }
            }
            Grid {
                id:num
                x: 115
                y: 120
                width: 200
                height:250
                padding: 10
                columns: 3
                rows: 4
                Button {
                    id: button1
                    width: 50
                    height:50
                    text: qsTr("1")
                    onClicked: passwd.insert(passwd.text.length,"1")
                }
                Button {
                    id: button2
                    width: 50
                    height:50
                    text: qsTr("2")
                    onClicked: passwd.insert(passwd.text.length,"2")
                }
                Button {
                    id: button3
                    width: 50
                    height:50
                    text: qsTr("3")
                    onClicked: passwd.insert(passwd.text.length,"3")
                }
                Button {
                    id: button4
                    width: 50
                    height:50
                    text: qsTr("4")
                    onClicked: passwd.insert(passwd.text.length,"4")
                }
                Button {
                    id: button5
                    width: 50
                    height:50
                    text: qsTr("5")
                    onClicked: passwd.insert(passwd.text.length,"5")
                }
                Button {
                    id: button6
                    width: 50
                    height:50
                    text: qsTr("6")
                    onClicked: passwd.insert(passwd.text.length,"6")
                }
                Button {
                    id: button7
                    width: 50
                    height:50
                    text: qsTr("7")
                    onClicked: passwd.insert(passwd.text.length,"7")
                }
                Button {
                    id: button8
                    width: 50
                    height:50
                    text: qsTr("8")
                    onClicked: passwd.insert(passwd.text.length,"8")
                }
                Button {
                    id: button9
                    width: 50
                    height:50
                    text: qsTr("9")
                    onClicked: passwd.insert(passwd.text.length,"9")
                }
                Button {
                    id: button0
                    width: 50
                    height:50
                    text: qsTr("0")
                    onClicked: passwd.insert(passwd.text.length,"0")
                }
                Button {
                    id: button10
                    width: 50
                    height:50
                    text: qsTr("<-")
                    onClicked: passwd.remove(passwd.text.length-1,passwd.text.length)
                }

            }
            Rectangle{
                width: parent.width
                height:60
                y:parent.height-60
                border.color: "blue"
                Button{
                    x:250;y:10
                    width: 60
                    height: 40
                    text: "登陆"
                    onClicked: {
//                      myPopup.close()
                       // dboperate.connect()

                        if(username.match("用户管理员"))
                        {authority=user.findUserAuthority("lt",passwd.text)}
                        if(username.match("系统管理员"))
                        {authority=user.findUserAuthority("lmx",passwd.text)}
                        if(username.match("客人"))
                        {authority=user.findUserAuthority("bxr",passwd.text)}
=======
                        //user.findUserAuthority("lmx","123456")
                        draw.drawline();

                        myPopup.close()
                        console.log(authority)
                    }
                }
                Button{
                    x:320;y:10
                    width: 60
                    height: 40
                    text: "取消"
                    onClicked: {
                        myPopup.close()
                    }
                }
            }
        }
    }

    Rectangle {
        id: uppertop
        x: 0
        y: 0
        width: 1280
        height: 25
        color: "cadetblue"
        border.color: "black"
        border.width: 1
        Rectangle {
            id: login
            x: 10
            y: 1
            width: 140
            height: 25
            color: "darkblue"
            Text {
                text: "用户登录"
                anchors.centerIn: parent
                color: "white"
                font.family: "Ubuntu"
                font.pixelSize: 20
            }
        }
        Rectangle {
            id: mainscreen
            x: login.x + 160
            y: 1
            width: 140
            height: 25
            color: "darkblue"
            Text {
                text: "主画面"
                anchors.centerIn: parent
                color: "white"
                font.family: "Ubuntu"
                font.pixelSize: 20
            }
        }
        Rectangle {
            id: setparamter
            x: login.x + 160 * 2
            y: 1
            width: 140
            height: 25
            color: "darkblue"
            Text {
                text: "参数设置"
                anchors.centerIn: parent
                color: "white"
                font.family: "Ubuntu"
                font.pixelSize: 20
            }
        }
        Rectangle {
            id: realtimecyrve
            x: login.x + 160 * 3
            y: 1
            width: 140
            height: 25
            color: "darkblue"
            Text {
                text: "实时曲线"
                anchors.centerIn: parent
                color: "white"
                font.family: "Ubuntu"
                font.pixelSize: 20
            }
        }
        Rectangle {
            id: historydata
            x: login.x + 160 * 4
            y: 1
            width: 140
            height: 25
            color: "darkblue"
            Text {
                text: "历史数据"
                anchors.centerIn: parent
                color: "white"
                font.family: "Ubuntu"
                font.pixelSize: 20
            }
        }
        Rectangle {
            id: alaertinfo
            x: login.x + 160 * 5
            y: 1
            width: 140
            height: 25
            color: "darkblue"
            Text {
                text: "报警信息"
                anchors.centerIn: parent
                color: "white"
                font.family: "Ubuntu"
                font.pixelSize: 20
            }
        }
        Rectangle {
            id: systemprocess
            x: login.x + 160 * 6
            y: 1
            width: 140
            height: 25
            color: "darkblue"
            Text {
                text: "系统流程"
                anchors.centerIn: parent
                color: "white"
                font.family: "Ubuntu"
                font.pixelSize: 20
            }
        }
        Rectangle {
            id: quit
            x: login.x + 160 * 7
            y: 1
            width: 140
            height: 25
            color: "darkblue"
            Text {
                text: "退出系统"
                anchors.centerIn: parent
                color: "white"
                font.family: "Ubuntu"
                font.pixelSize: 20
            }
        }
    }
   // Header{}
    Rectangle {
        id: time
        x: systemprocess.x + 30
        y: 100
        width: 180
        height: 25
        color: "black"
        Text {
            text: "2017-10-31 9:30:30"
            anchors.centerIn: parent
            color: "white"
            font.family: "Ubuntu"
            font.pixelSize: 20
        }
    }

    Rectangle {
        id: admin
        x: mainscreen.x - 20
        y: 200
        width: 140
        height: 25
        color: "darkblue"
        Text {
            text: "用户管理"
            anchors.centerIn: parent
            color: "white"
            font.family: "Ubuntu"
            font.pixelSize: 20
        }
    }
    Rectangle {
        id: login2
        x: mainscreen.x - 20
        y: admin.y + 75
        width: 140
        height: 25
        color: "darkblue"
        Text {
            text: "用户登录"
            anchors.centerIn: parent
            color: "white"
            font.family: "Ubuntu"
            font.pixelSize: 20
        }
        MouseArea {
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton | Qt.RightButton

            onClicked: {
                myPopup.open()
            }
        }
    }
    Rectangle {
        id: logout
        x: mainscreen.x - 20
        y: admin.y + 150
        width: 140
        height: 25
        color: "darkblue"
        Text {
            text: "用户注销"
            anchors.centerIn: parent
            color: "white"
            font.family: "Ubuntu"
            font.pixelSize: 20
        }
    }
    Text {
        id: guestText
        x: mainscreen.x
        y: admin.y + 270
        text: "当前用户"
        color: "white"
        font.family: "Ubuntu"
        font.pixelSize: 20
    }
    Rectangle {
        id: guest
        x: mainscreen.x - 20
        y: admin.y + 300
        width: 140
        height: 25
        color: "darkblue"
        Text {
            text: "客人"
            anchors.centerIn: parent
            color: "white"
            font.family: "Ubuntu"
            font.pixelSize: 20
        }
    }

    Text {
        id: systemName
        x: setparamter.x + 100
        y: admin.y - 20
        text: "烟气数据监测系统"
        color: "white"
        font.family: "Ubuntu"
        font.pixelSize: 50
    }
}
